﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.StoretakeVMs
{
    public partial class StoretakeListVM : BasePagedListVM<Storetake_View, StoretakeSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Storetake_View>> InitGridHeader()
        {
            return new List<GridColumn<Storetake_View>>{
                
                this.MakeGridHeader(x => x.Storetake_Material).SetTitle(@Localizer["Page.盘点物料"].Value),
                this.MakeGridHeader(x => x.Storetake_MaterialName).SetTitle(@Localizer["Page.盘点物料"].Value),
                this.MakeGridHeader(x => x.Storetake_Sheet).SetTitle(@Localizer["Page.盘点单号"].Value),
                this.MakeGridHeader(x => x.Storetake_SheetCode).SetTitle(@Localizer["Page.盘点单号"].Value),
                this.MakeGridHeader(x => x.Storetake_ExpectedQty).SetTitle(@Localizer["Page.系统库存数"].Value),
                this.MakeGridHeader(x => x.Storetake_CountedQty).SetTitle(@Localizer["Page.盘点实际数"].Value),
                this.MakeGridHeader(x => x.Storetake_VarianceQty).SetTitle(@Localizer["Page.差异数量"].Value),
                this.MakeGridHeader(x => x.Storetake_StocktakeDate).SetTitle(@Localizer["Page.盘点时间"].Value),
                this.MakeGridHeader(x => x.Storetake_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Storetake_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Storetake_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Storetake_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Storetake_View> GetSearchQuery()
        {
            var query = DC.Set<Storetake>()
                
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckEqual(Searcher.SheetCode, x=>x.SheetCode)
                .CheckEqual(Searcher.ExpectedQty, x=>x.ExpectedQty)
                .CheckEqual(Searcher.CountedQty, x=>x.CountedQty)
                .CheckEqual(Searcher.VarianceQty, x=>x.VarianceQty)
                .CheckBetween(Searcher.StocktakeDate?.GetStartTime(), Searcher.StocktakeDate?.GetEndTime(), x => x.StocktakeDate, includeMax: false)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Storetake_View
                {
				    ID = x.ID,
                    
                    Storetake_Material = x.Material.TenantCode,
                    Storetake_MaterialName = x.MaterialName,
                    Storetake_Sheet = x.Sheet.TenantCode,
                    Storetake_SheetCode = x.SheetCode,
                    Storetake_ExpectedQty = x.ExpectedQty,
                    Storetake_CountedQty = x.CountedQty,
                    Storetake_VarianceQty = x.VarianceQty,
                    Storetake_StocktakeDate = x.StocktakeDate,
                    Storetake_CreateTime = x.CreateTime,
                    Storetake_UpdateTime = x.UpdateTime,
                    Storetake_CreateBy = x.CreateBy,
                    Storetake_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Storetake_View: Storetake
    {
        
        public string Storetake_Material { get; set; }
        public string Storetake_MaterialName { get; set; }
        public string Storetake_Sheet { get; set; }
        public long? Storetake_SheetCode { get; set; }
        public decimal? Storetake_ExpectedQty { get; set; }
        public decimal? Storetake_CountedQty { get; set; }
        public decimal? Storetake_VarianceQty { get; set; }
        public DateTime? Storetake_StocktakeDate { get; set; }
        public DateTime? Storetake_CreateTime { get; set; }
        public DateTime? Storetake_UpdateTime { get; set; }
        public string Storetake_CreateBy { get; set; }
        public string Storetake_UpdateBy { get; set; }

    }

}